.TH std::filesystem::path::make_preferred 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::filesystem::path::make_preferred \- std::filesystem::path::make_preferred

.SH Synopsis
   path& make_preferred();  \fI(since C++17)\fP

   Converts all directory separators in the generic-format view of the path to the
   preferred directory separator.

   For example, on Windows, where \\ is the preferred separator, the path foo/bar will
   be converted to foo\\bar.

.SH Parameters

   \fI(none)\fP

.SH Return value

   *this

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Example

   Windows can use / as a separator, but prefers \\, so make_preferred converts the
   forward slashes to backslashes. On the other hand, POSIX does not use \\ as a
   separator, because backslashes are valid filename characters — the Windows path on
   POSIX actually refers to a file with the name "a\\\\b\\\\c". For this reason the
   "separators" are not converted.


// Run this code

 #include <filesystem>
 #include <iostream>

 int main()
 {
     std::filesystem::path
         windows_path("a\\\\b\\\\c"),
         posix_path("a/b/c");

     std::cout
         << "Windows path: "
         << windows_path << " -> "
         << windows_path.make_preferred() << '\\n'
         << "POSIX path: "
         << posix_path << " -> "
         << posix_path.make_preferred() << '\\n';
 }

.SH Output:

 // on Windows
 Windows path: "a\\\\b\\\\c" -> "a\\\\b\\\\c"
 POSIX path: "a/b/c" -> "a\\\\b\\\\c"

 // on POSIX
 Windows path: "a\\\\b\\\\c" -> "a\\\\b\\\\c"
 POSIX path: "a/b/c" -> "a/b/c"

.SH See also

                        alternative directory separator which may be used in addition
   constexpr value_type to the portable /. On Windows, this is the backslash character
   preferred_separator  \\. On POSIX, this is the same forward slash / as the portable
   \fB[static]\fP             separator
                        \fI(public static member constant)\fP
